const jwt = require("jsonwebtoken")

jwtUtil = {
  settoken(str) {
    let tokenkey = jwt.sign(str, 'apache', {
      expiresIn: '1h'
    })
    return tokenkey
  },
  parestoken(str) {
    let decoded = jwt.verify(str, 'apache', function (err, decoded){
      if (err) {
        if (err.name === 'TokenExpiredError') {
          return 'Token过期！'
        } else {
          return 'Token无效！'
        }
      } else {
        return decoded
      }
    })
    return decoded
  }
}

module.exports = jwtUtil